﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Details : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DropDownList26.Visible = CheckBox2.Checked;
        Button1.Visible=CheckBox2.Checked;
        
        if (!Page.IsPostBack)
        {
            FillDropdownCategory();
            FillDropdownMerk();
            FillDropdownProduct();
            FillDropdownEigenschappen();
        }
    }
  
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList29.Visible == true)
            DropDownList30.Visible = true;
        else 
            DropDownList29.Visible = true;
    }

    protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonList2.SelectedValue== "vast")
        {
            DropDownListVanToepassingOp.Items[3].Enabled = false;
            LabelEenheid.Text = "€";
        }
        else
            DropDownListVanToepassingOp.Items[3].Enabled = true;
        //{
        //    if (RadioButtonList2.SelectedValue== "percent")
        //        LabelEenheid.Text="%";
        //    else
        //        LabelEenheid.Text = "€";

        //    DropDownListVanToepassingOp.Items[2].Enabled = true; 
        //}

    }

    private void FillDropdownMerk()
    {
        DropDownListMerken.DataSource = SqlDataSourceMerken;
        DropDownListMerken.DataTextField = "merknaam";
        DropDownListMerken.DataValueField = "idMerk";
        DropDownListMerken.DataBind();
        DropDownListMerken.Items.Insert(0, new ListItem("--Selecteer een merk--", "0"));
    }

    private void FillDropdownEigenschappen()
    {
        if (DropDownListProducten.SelectedIndex > 0)
        {
            DropDownListEigenschappen.DataSource = SqlDataSourceEigenschappen;
            DropDownListEigenschappen.DataTextField = "waarde";
            DropDownListEigenschappen.DataValueField = "idSpecificatieWaarde";
            DropDownListEigenschappen.DataBind();
            DropDownListEigenschappen.Items.Insert(0, new ListItem("--Selecteer een eigenschap--", "0"));
        }
        else
        {
            DropDownListEigenschappen.DataSource = SqlDataSourceAlleEigenschappen;
            DropDownListEigenschappen.DataTextField = "waarde";
            DropDownListEigenschappen.DataValueField = "waarde";
            DropDownListEigenschappen.DataBind();
            DropDownListEigenschappen.Items.Insert(0, new ListItem("--Selecteer een eigenschap--", "0"));
        }
    }

    protected void FillDropdownCategory()
    {
        DropDownListCategory.DataSource = SqlDataSourceCategorie;
        DropDownListCategory.DataTextField = "waarde";
        DropDownListCategory.DataValueField = "idSpecificatieWaarde";
        DropDownListCategory.DataBind();
        DropDownListCategory.Items.Insert(0, new ListItem("--Selecteer een categorie--", "0"));
    }

    protected void FillDropdownProduct()
    {
        if (DropDownListCategory.SelectedIndex > 0)
        {
            DropDownListProducten.DataSource = SqlDataSourceProductenCategorie;
            DropDownListProducten.DataTextField = "naam";
            DropDownListProducten.DataValueField = "artikelNr";
            DropDownListProducten.DataBind();
            DropDownListProducten.Items.Insert(0, new ListItem("--Selecteer een product--", "0"));
        }
        else
        {
            DropDownListProducten.DataSource = SqlDataSourceAlleProducten;
            DropDownListProducten.DataTextField = "naam";
            DropDownListProducten.DataValueField = "artikelNr";
            DropDownListProducten.DataBind();
            DropDownListProducten.Items.Insert(0, new ListItem("--Selecteer een product--", "0"));
        }
        FillDropdownEigenschappen();
    }

    protected void ButtonAdd_Click(object sender, EventArgs e)
    {
        if (PanelVoorwaarde.Visible == false)
            PanelVoorwaarde.Visible = true;
        else
            PanelVoorwaarde2.Visible = true;
    }
    protected void ButtonVerwijder_Click(object sender, EventArgs e)
    {
        if (PanelVoorwaarde2.Visible == true)
        {
            PanelVoorwaarde2.Visible = false;
            PanelVoorwaarden2.Visible = false;
            PanelVerzendFormule2.Visible = false;
          
            DropDownListVanToepassingOp0.SelectedIndex = 0;
        }
        else
        {
            PanelProduct.Visible = false;
            PanelVoorwaarde.Visible = false;
            PanelBetaalmethode.Visible = false;
            PanelVerzendFormule.Visible = false;
        }
    }

    protected void DropDownListProducten_SelectedIndexChanged(object sender, EventArgs e)
    {
        FillDropdownEigenschappen();
    }

    protected void DropDownListEigenschappen_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownListWaarde.DataBind();
    }
    protected void DropDownListCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        FillDropdownProduct();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (((DropDownList)sender).SelectedValue == "product")
        {
            SetPanelVisible(false);
            PanelProduct.Visible = true;
        }
        else if (((DropDownList)sender).SelectedValue == "betaal")
        {
            SetPanelVisible(false);
            PanelBetaalmethode.Visible = true;
        }
        if (((DropDownList)sender).SelectedValue == "verzend")
        {
            SetPanelVisible(false);
            PanelVerzendFormule.Visible = true;
        }
    }
    private void SetPanelVisible(bool visible)
    {
        PanelProduct.Visible = visible;
        PanelBetaalmethode.Visible = visible;
        PanelVerzendFormule.Visible = visible;
    }
    protected void DropDownList14_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (((DropDownList)sender).SelectedValue == "alle")
        {
            TextBoxAantal.Visible = false;
            DropDownListAantal.Visible = false;
        }
        else
        {
            TextBoxAantal.Visible = true;
            DropDownListAantal.Visible = true;
        }

    }


    protected void DropDownListVanToepassingOp_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (((DropDownList)sender).SelectedIndex == 1)
        {
            PanelVoorwaarde.Visible = true;
            DropDownListVanToepassingOp0.SelectedIndex = 1;
            PanelProduct.Visible = true;
            DropDownList14.Items[2].Enabled = true;
        }
        else
        {
            PanelVoorwaarde.Visible = false;
            DropDownListVanToepassingOp0.SelectedIndex = 0;
            PanelProduct.Visible = false;
            DropDownList14.Items[2].Enabled = false;
        }
    }

    private void SetSpecificProduct()
    {
        PanelProductkorting.Visible = true;
        DropDownListMerkenKorting.DataSource = SqlDataSourceMerken;
        DropDownListMerkenKorting.DataTextField = "merknaam";
        DropDownListMerkenKorting.DataValueField = "idMerk";
        DropDownListMerkenKorting.DataBind();
        DropDownListMerkenKorting.Items.Insert(0, new ListItem("--Selecteer een merk--", "0"));
        DropDownListCategoryKorting.DataSource = SqlDataSourceCategorie;
        DropDownListCategoryKorting.DataTextField = "waarde";
        DropDownListCategoryKorting.DataValueField = "idSpecificatieWaarde";
        DropDownListCategoryKorting.DataBind();
        DropDownListCategoryKorting.Items.Insert(0, new ListItem("--Selecteer een categorie--", "0"));
        DropDownListEigenschappenKorting.DataSource = SqlDataSourceEigenschappen;
        DropDownListEigenschappenKorting.DataTextField = "waarde";
        DropDownListEigenschappenKorting.DataValueField = "idSpecificatieNamen";
        DropDownListEigenschappenKorting.DataBind();
        DropDownListEigenschappenKorting.Items.Insert(0, new ListItem("--Selecteer een eigenschap--", "0"));
        DropDownListProductenKorting.DataSource = SqlDataSourceProductenCategorie;
        DropDownListProductenKorting.DataTextField = "naam";
        DropDownListProductenKorting.DataValueField = "artikelNr";
        DropDownListProductenKorting.DataBind();
        DropDownListProductenKorting.Items.Insert(0, new ListItem("--Selecteer een product--", "0"));
    }
    
    protected void DropDownListVanToepassingOp1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (((DropDownList)sender).SelectedIndex == 2)
        {
            PanelVerzendFormule2.Visible = false;
            PanelVoorwaarden2.Visible = true;
        }
        else
        {
            PanelVerzendFormule2.Visible = true;
            PanelVoorwaarden2.Visible = false;
        }
    }
}
